import axios from 'axios';

const ajax = {
  // 获取i18n种类
  GET_LANGUAGE_TYPE: '/get/i18n_type',

  // 获取首页menuList
  GET_MENU_LIST: 'homePageMenuImgList',
};
// 获取二级子级菜单
const GET_CHILD_MENU = 'v1/menu/submenu/list/{menuId}?'
// 获取有权限的子菜单
const GET_GRANTED_SUBMENU = 'v1/menu/list'

// 增加前缀
let INTERFACE = {};
for (let key in ajax) {
  INTERFACE[key] = '/api' + ajax[key];
}
/**
 * 获取 i18n 的种类
 */
function getI18nType() {
  // 这里需要先调用后端保存的语言
  return axios.get(INTERFACE.GET_LANGUAGE_TYPE);
}

/**
 * 获取头部导航菜单
 */
function getHeaderList() {
  var data = {
    parentMenuValue: '/',
    serviceName: window.host.serviceName,
    httpMethod: 'GET',
    parentType: 'FRONTEND_DOMAIN',
    childType: 'FRONTEND_URL'
  }
  return axios.get(GET_GRANTED_SUBMENU + '?', {params: data}).catch(function (error) {
  // return axios.get(GET_CURRENT_HEADERLIST + '?', {params: data}).catch(function (error) {
    console.log(error)
  });
}

/**
 * 获取首页menuList
 */
function getMenuList() {
  return axios.get(INTERFACE.GET_MENU_LIST).catch(function (error) {
    window.Alert(error);
  });
}

// 退出系统
function logout() {
  return axios.get('auth/user/logout?').catch(function (error) {
    window.Alert(error);
  });
}
/**
 * 获取子级菜单
 */
function getChildmenu(menuId) {
  return axios.get(GET_CHILD_MENU.replace('{menuId}', menuId)).catch(function (error) {
    console.log(error)
  });
}
export default {
  getI18nType,
  getHeaderList,
  getMenuList,
  logout,
  getChildmenu
};
